package com.tree.xinhe.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.tree.xinhe.R;
import com.tree.xinhe.entity.AdImg;

import java.util.List;

/**
 * Created by Administrator on 2016/12/27.
 */
public class GridAdapter extends RecyclerView.Adapter<GridAdapter.GridViewHolder>{

    private LayoutInflater inflater;
    private List<AdImg> list;
    private Context ctx;


    public GridAdapter(Context context, List<AdImg> list) {
        this.inflater = LayoutInflater.from(context);
        this.list = list;
        this.ctx = context;
    }

    @Override
    public GridViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=inflater.inflate(R.layout.adapter_recycler_grid,null);
        GridViewHolder holder=new GridViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(GridViewHolder holder, int position) {
        String imgUrl = "http://120.27.97.93:8080/xhsc"+list.get(position).getImgUrl();
        Glide.with(ctx).load(imgUrl).into(holder.img);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class GridViewHolder extends RecyclerView.ViewHolder{

        ImageView img;

        public GridViewHolder(View itemView) {
            super(itemView);
            img=(ImageView)itemView.findViewById(R.id.img);
        }
    }

}
